package com.orangeumbrella;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.LinearLayout;

import com.easylib.base.BaseActivity;
import com.guyj.CommonAdapter;
import com.guyj.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

public class CommunityActivity extends BaseActivity {

    @Bind(R.id.recycler1)
    RecyclerView recycler1;
    @Bind(R.id.recycler2)
    RecyclerView recycler2;
    @Bind(R.id.activity_community)
    LinearLayout activityCommunity;
    LinearLayoutManager llm1;
    LinearLayoutManager llm2;
    CommonAdapter<String> adapter1;
    CommonAdapter<String> adapter2;
    List<String> datas1;
    List<String> datas2;
    List<String> datasTitle;
    SparseArray<List<String>> datasContent;


    @Override
    public int getContentViewId() {
        return R.layout.activity_community;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initVariable() {
        llm1 = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        llm2 = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        datas1 = new ArrayList<>();
        datas2 = new ArrayList<>();
        datasTitle = new ArrayList<>();
        datasContent = new SparseArray();
        datas1.add("防身小贴士1");
        datas1.add("防身小贴士2");
        datas1.add("防身小贴士3");
        datas1.add("防身小贴士4");
        datas1.add("防身小贴士5");
        datas2.add("达人防身术1");
        datas2.add("达人防身术2");
        datas2.add("达人防身术3");
        datas2.add("达人防身术4");
        datas2.add("达人防身术5");
        datas2.add("达人防身术6");
        datas2.add("达人防身术7");
        datas2.add("达人防身术8");
        datas2.add("达人防身术9");
        datas2.add("达人防身术10");
        datasTitle.add("防身小贴士");
        datasTitle.add("达人防身术");
        datasContent.put(0, datas1);
        datasContent.put(1, datas2);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        recycler1.setLayoutManager(llm1);
        recycler2.setLayoutManager(llm2);
        recycler1.setAdapter(adapter1 = new CommonAdapter<String>(mContext, R.layout.item_title, datasTitle) {
            @Override
            protected void convert(ViewHolder viewHolder, String s, final int i) {
                viewHolder.setText(R.id.tv_title, s);
                viewHolder.setOnClickListener(R.id.ll_root, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        adapter2.setDatas(datasContent.get(i));
                    }
                });
            }
        });
        recycler2.setAdapter(adapter2 = new CommonAdapter<String>(mContext, R.layout.item_title, datas1) {
            @Override
            protected void convert(ViewHolder viewHolder, String s, int i) {
                viewHolder.setText(R.id.tv_title, s);
            }
        });
    }

}
